<template>
	<view>
		<u-navbar title-color="#000" :isBack="true" back-icon-color="#000" height="60" title="登录"></u-navbar>
		<view class="input-box">
			<view class="input-item">
				<view class="input-label">手机号</view>
				<view class="input-body">
					<input v-model="phone" maxlength="11" type="number" placeholder="请输入手机号" class="input">
				</view>
			</view>
			<view class="input-item">
				<view class="input-label">密码</view>
				<view class="input-body">
					<input v-model="password" type="text" :password="isHidePassword?true:false" style="margin-right: 50upx;"
					 placeholder="请输入密码" maxlength="20" class="input" />
					<image @click="isHidePasswordClick" class="eye" :src="isHidePassword?'/static/img/attention.png':'/static/img/attention_forbid.png'"></image>
				</view>
			</view>
			<view class="select">
				<text></text>
				<navigator url="/pages/register/register" hover-class="none">注册</navigator>
			</view>
		</view>
		<button class="button" @click="submit">登录</button>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isHidePassword: true,
				phone: "",
				password: ""
			};
		},
		methods: {
			isHidePasswordClick() {
				this.isHidePassword = !this.isHidePassword
			},
			submit() {
				let data = {
					userPhone: this.phone,
					userPass: this.password
				}
				let valLoginRes = this.$validate.validate(data, [{
						name: 'userPhone',
						type: 'phone',
						required: 'true',
						errmsg: '请输入的正确的手机号'
					},
					{
						name: 'userPass',
						type: 'required',
						errmsg: '密码不能为空'
					}
				])
				this.$api.login(data).then(res => {
					if (res.code) {
						this.$comm.successToShow(res.data.msg, () => {
							this.$store.dispatch('setUserInfoAction', res.data.userInfo[0])
							this.$store.dispatch('saveUserTokenAction', res.data.Token)
							this.$comm.reLaunch("/pages/index/index")
						})
					} else {
						this.$comm.errorToShow(res.data.msg)
					}
				})
			}
		}
	}
</script>
<style lang="scss">
	page {
		background-color: #FFFFFF;
		min-height: 100vh;
	}
</style>
